import sqlite3, sys, os

# usage: add-stadium.py name place team

def ConnectToDB(dbName):
    db = sqlite3.connect(dbName)
    
    return db
    
def AddStadium():
    conn.execute("insert into stadiums (Name, Place, Team) values (?, ?, ?)", (sys.argv[1], sys.argv[2], sys.argv[3]))
    conn.execute("select last_insert_rowid()")
    return conn.fetchone()[0]
    
def AddSynonyms(teamID):
    for i in range(0, len(sys.argv) - 4 - 1):
        conn.execute("insert into teamsynonyms (TeamID, Synonym) values (?, ?)", (teamID, sys.argv[i + 5]))
    
    

dbName = "teams.db"
if (not os.path.exists(dbName)):
    print("Не найден файл базы данных, проверьте его доступность")
    sys.exit(1)
    
if (len(sys.argv) < 3):
    print ("использование: add-stadium.py name place team")
    sys.exit(1)
        
db = ConnectToDB(dbName)
conn = db.cursor()

sys.argv = ("\"" + "\" \"".join(sys.argv) + "\"")[1:-1].split("\" \"")

AddStadium()
#AddSynonyms(teamID)

db.commit()
db.close()